package com.wx.controller;

import java.util.ArrayList;
import java.util.concurrent.*;

/**
 * @ClassName Test
 * @Description 创建线程池及获取线程返回值
 * @Author wx
 * @Date 2019/10/29 3:31 PM
 * @Version 1.0
 */
public class Test implements Callable<String>{

    private String id;

    public Test(String id) {
        this.id = id;
    }

    @Override
    public String call() throws Exception {
        Thread.sleep(3000);
        return create(id);
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService service = Executors.newFixedThreadPool(4);//创建四个线程
        Future<String> future = service.submit(new Test("3"));//传入2计算
        String s = future.get();
        System.out.println(s);
    }
    public String create(String id){
        String result="";
        if("2".equals(id)){
            result="4";
        }else{
            result="测试其他倍数";
        }
        return result;
    }
}
